package com.example.xiaozu.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;
import com.example.xiaozu.R;
import androidx.appcompat.app.AppCompatActivity;

public class ChangePasswordActivity extends AppCompatActivity {
    private EditText etNewPassword;
    private String username;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);

        username = getIntent().getStringExtra("username");
        etNewPassword = findViewById(R.id.et_new_password);

        findViewById(R.id.btn_confirm).setOnClickListener(v -> {
            String newPassword = etNewPassword.getText().toString();
            if (newPassword.isEmpty()) {
                Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
                return;
            }

            // 更新密码
            SharedPreferences.Editor editor = getSharedPreferences("users", MODE_PRIVATE).edit();
            editor.putString(username + "_password", newPassword);
            editor.apply();

            Toast.makeText(this, "密码修改成功", Toast.LENGTH_SHORT).show();
            finish();
        });
    }
}
